package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.Subject;
import com.rh.mapper.SubjectMapper;
import com.rh.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class SubjectServiceImpl implements SubjectService {
    @Autowired
    private SubjectMapper subjectMapper;
    @Override
    public void addMethod(Subject subject) {
     subjectMapper.addMethod(subject);
    }

    @Override
    public void deleteMethod(Integer subjectId) {
    subjectMapper.deleteMethod(subjectId);
    }

    @Override
    public void updateMethod(Subject subject) {
    subjectMapper.updateMethod(subject);
    }

    @Override
    public Page getSubjectPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Subject> methodAll = subjectMapper.getMethodAll();
        PageInfo<Subject>info=new PageInfo<>(methodAll);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setPageCount(info.getPages());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setCount(info.getTotal());
        page.setPage(info.getList());
        return page;
    }


    @Override
    public Subject getMethodAllById(Integer subjectId) {
        return subjectMapper.getMethodAllById(subjectId);
    }
}
